package com.rem.mp.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

/**
 * 对字段进行填充
 *
 * @Author Rem
 * @Date 2020-03-01
 */

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    /**
     * 对字段插入时进行操作
     *
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        Object password = getFieldValByName("password", metaObject);
        if (null == password) {
            //密码为，自动填充888888
            setFieldValByName("password", "888888", metaObject);
        }
    }

    /**
     * 对字段更新时进行操作
     *
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {

    }
}
